<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div style="padding-bottom:200px" class="layui-form layuimini-form">

    <input type="hidden" name="id" value="{$res.id}"/>


    <div class="layui-form-item">
        <blockquote class="layui-elem-quote layui-text">
            商品名称：{$res.0.bizpro_name}
        </blockquote>
        <div class="">
            <table id="table" class="layui-table">
                <colgroup>
                    <col width="150">
                    <col width="200">
                    <col width="150">
                    <col width="200">
                    <col width="200">
                    <col width="200">
                    <col width="200">
                    <col width="200">
                </colgroup>
                <thead>
                <tr>
                    <th>订单编号</th>
                    <th>收货人名称</th>
                    <th>手机</th>
                    <th>地址</th>
                    <th>商品编号</th>
                    <th>商品数量</th>
                    <th>商品规格</th>
                    <th>商品进价</th>
                    <th>供应商下单</th>
                </tr>
                </thead>
                <tbody>
                {volist name="res" id="vo"}
                <tr id="{$vo.id}">
                    <td>{$vo.order_number}</td>
                    <td>{$vo.receive_name}</td>
                    <td>{$vo.receive_phone}</td>
                    <td>{$vo.province}{$vo.city}{$vo.area}{$vo.address}</td>
                    <td>{$vo.bizpro_number}</td>
                    <td onclick='writeNum("{$vo.order_id}","{$vo.bizpro_id}","{$vo.buy_num}")'>{$vo.buy_num}</td>
                    <td>{$vo.bizpro_spec_value}</td>
                    <td onclick='writePursh_price("{$vo.order_id}","{$vo.bizpro_id}","{$vo.pursh_price}")'>
                        {$vo.pursh_price}
                    </td>
                    <td>{if condition="$vo.orderdetail_status==1"}已下单 {else}未下单{/if}</td>
                </tr>
                {/volist}
                </tbody>
            </table>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="" style="display: flex">

            <label class="layui-form-label required">合计金额:</label>

            <p style="height: 38px; line-height: 2;font-size: 1.5em;width: 90%;color:red">{$total_arr.tosendprice}￥</p>


            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">点击下单</button>

            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="print">打印订单</button>

            <a href="/admin/Order/MkExportData?bizpro_id={$bizpro_id}" class="layui-btn layui-btn-normal" lay-submit
               lay-filter="exportBtn">导出订单</a>


        </div>

    </div>
    <!--<div class="layui-form-item">-->
    <!--<div class="layui-input-block">-->
    <!--<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">点击下单</button>-->
    <!--</div>-->
    <!--</div>-->

</div>
{include file="public/footer" /}
<!--<script src="/static/admin/order/mkorder.js?v={$Think.const.TIMESTAMP}" charset="utf-8"></script>-->
</body>
<script>
    layui.use(['form', 'laydate', 'table', 'loading'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let id = ''
            $("tr").each(function (index, val) {
                if (typeof  $(val).attr('id') != 'undefined') {
                    id += $(val).attr('id') + ','
                }

            })
            //发异步，把数据提交给php
            $.ajax({
                url: '/admin/order/DoMk',
                type: 'post',
                dataType: 'json',
                data: {id: id},
                success: function (res) {

                    if (res.status == true) {
                        layer.msg('下单成功', {icon: 1, time: 1000},
                            function () {
                                parent.location.reload();
                            })

                    } else {
                        layer.open({
                            title: '错误信息',
                            content: '<span style="color:red">' + res.code + ':</span>' + res.msg
                        })
                        return false
                    }
                },
                error: function (re) {

                    layer.open({
                        title: '错误信息',
                        content: '<span style="color:red">' + re.responseJSON.errorCode + ':</span>' + re.responseJSON.msg
                    })
                }
            });

        });

        form.on('submit(print)', function (data) {
            console.log($("#table").prop("outerHTML"));
            let  u = window.open("打印窗口", "_blank"),
                 h = ["<style>", "body{font-size: 12px; color: #666;}", "table{width: 100%; border-collapse: collapse; border-spacing: 0;}", "th,td{line-height: 20px; padding: 9px 15px; border: 1px solid #ccc; text-align: left; font-size: 12px; color: #666;}", "a{color: #666; text-decoration:none;}", "*.layui-hide{display: none}", "</style>"].join("");
                 u.document.write(h + $("#table").prop("outerHTML")),
                u.document.close(),
                u.print(),
                u.close()
        })


    });
</script>
<script>
    //修改数量
    function writeNum(orderId, bizproId, buy_num) {
        layer.prompt({formType: 0, title: '修改数量', number: 1, value: [buy_num]}, function (value, index, elem) {
            console.log(orderId, bizproId)
            $.ajax({
                url: '/admin/order/orderWrite',
                type: 'post',
                dataType: 'json',
                data: {
                    buy_num: value,
                    mark: 'num',
                    orderId: orderId,
                    bizproId: bizproId
                },
                success: function (res) {
                    if (res.status == true) {
                        layer.msg('修改成功', {icon: 1, time: 1000},
                            function () {
                                location.reload();
                            })

                    } else {
                        layer.open({
                            title: '错误信息',
                            content: '<span style="color:red">' + res.code + ':</span>' + res.msg
                        })
                        return false
                    }
                },
                error: function (re) {
                    layer.msg('错误信息')


                }
            });
        })
    }

    //修改进货价
    function writePursh_price(orderId, bizproId, purshPrice) {
        layer.prompt({formType: 0, title: '修改进货价格', number: 1, value: [purshPrice]}, function (value, index, elem) {
            $.ajax({
                url: '/admin/order/orderWrite',
                type: 'post',
                dataType: 'json',
                data: {purshPrice: value, mark: 'pursh_price', orderId: orderId, bizproId: bizproId},
                success: function (res) {
                    if (res.status == true) {
                        layer.msg('修改成功', {icon: 1, time: 1000},
                            function () {
                                location.reload();
                            })

                    } else {
                        layer.open({
                            title: '错误信息',
                            content: '<span style="color:red">' + res.code + ':</span>' + res.msg
                        })
                        return false
                    }
                },
                error: function (re) {

                    layer.open({
                        title: '错误信息',
                        content: '<span style="color:red">' + re.responseJSON.errorCode + ':</span>' + re.responseJSON.msg
                    })
                }
            });
        })
    }
</script>
</html>